package org.hj.modules;

import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;
import org.hj.common.system.api.ISysBaseAPI;
import org.hj.modules.act.actmodel.service.ActModelService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

/**
 * 说明：启动流程用
 * 作者：Joson 2019-01-01
 */
public class AcStartController extends  AcBusinessController  {
	
	public String AppStatus="234";

	@Autowired
	public ISysBaseAPI sysBaseAPI;
	
	@Autowired
	private RuntimeService runtimeService; 		//与正在执行的流程实例和执行对象相关的Service(执行管理，包括启动、推进、删除流程实例等操作)

	@Autowired
	private ActModelService actModelService;
	
	/**通过KEY启动流程实例(不带变量)
	 * @param processInstanceKey //流程定义的KEY
	 * @return 返回流程实例ID
	 */
	protected String startProcessInstanceByKey(String processInstanceKey){
		ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processInstanceKey);			//用流程定义的KEY启动，会自动选择KEY相同的流程定义中最新版本的那个(KEY为模型中的流程唯一标识)
		return processInstance.getId();	//返回流程实例ID
	}
	
	/**通过KEY启动流程实例(带变量)
	 * @param processInstanceKey //流程定义的KEY
	 * @return 返回流程实例ID
	 */
	protected String startProcessInstanceByKeyHasVariables(String processInstanceKey,Map<String,Object> map){
		ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processInstanceKey, map);	//map存储变量 用流程定义的KEY启动，会自动选择KEY相同的流程定义中最新版本的那个(KEY为模型中的流程唯一标识)
		return processInstance.getId();	//返回流程实例ID
	}
	
	/**通过ID启动流程实例
	 * @param processInstanceId //流程定义的ID
	 * @return 返回流程实例ID
	 */
	protected String startProcessInstanceById(String processInstanceId){
		ProcessInstance processInstance = runtimeService.startProcessInstanceById(processInstanceId);			//用流程定义的ID启动
		return processInstance.getId();	//返回流程实例ID
	}

	/*
	 * 获取单证类型
	 * */
	protected String GetDicDocumentText(String Key)
	{
		String  text = sysBaseAPI.getDictTextByKey("document", Key);
		return text;
	}
	/*
	 * 获取审批加急状态
	 * */
	protected String GetDicStatus_enText(String Key)
	{
		String  text = sysBaseAPI.getDictTextByKey("status_en", Key);
		return text;
	}
	
	/*
	 * 获取币制
	 * */
	protected String GetDicCurrencyText(String Key)
	{
		String  text = sysBaseAPI.getDictTextByKey("currency", Key);
		return text;
	}
	
	
	/*
	 * 获取部门
	 * */
	protected String GetDeparmentText(String Key)
	{
		String  text =sysBaseAPI.getTableDictTextByCode("sys_depart", "depart_name", "org_code",Key);
		   
		return text;
	}



	//获取act_ru_task
	protected Map<Object,Object> getActRuTaskById(String id)
	{
		Map<Object,Object> map=actModelService.findActRuTaskById(id);

		return map;
	}
   
}
